﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Net;
using System.Windows;
using System.Windows.Controls;
using System.Windows.Documents;
using System.Windows.Input;
using System.Windows.Media;
using System.Windows.Media.Animation;
using System.Windows.Shapes;
using System.Json;
using System.Windows.Media.Imaging;
using WorkSpace.UI.Windows;
using WorkSpace.UI.Controls.Windows;
using WorkSpace.UI.WorkSpaceRef;

namespace WorkSpace.UI.Controls
{
    public partial class PackagePart : UserControl
    {
        private PersonalPackage _package;

        public PersonalPackage Package { get { return _package; } }

        public PackagePart(PersonalPackage package)
        {
            InitializeComponent();

            _package = package;

            this.Loaded += new RoutedEventHandler(CategoryPart_Loaded);
        }

        void CategoryPart_Loaded(object sender, RoutedEventArgs e)
        {
            LoadDatas();
        }

        public void LoadDatas()
        {
            WorkSpaceRef.WorkSpaceWebServiceSoapClient client = WorkSpaceModule.CreateWorkSpaceWebServiceProxy();
            client.GetPersonalLinksCompleted += new EventHandler<GetPersonalLinksCompletedEventArgs>(client_GetPersonalLinksCompleted);
            client.GetPersonalLinksAsync(_package.Id);
        }

        void client_GetPersonalLinksCompleted(object sender, GetPersonalLinksCompletedEventArgs e)
        {
            if (e.Error == null && e.Result.IsSuccess)
            {
                _ctlContainer.Children.Clear();

                foreach (PersonalLink item in e.Result.Data)
                {
                    LinkPart btn = new LinkPart(item.Link, _package.Account);
                    btn.Margin = new Thickness(5, 5, 0, 0);
                    _ctlContainer.Children.Add(btn);
                }
            }
        }
    }
}
